package com.ccys.cms.controller.discount;

import com.ccys.cms.service.discount.BinNumberService;
import com.ccys.common.vo.ResponseResult;
import com.ccys.db.dto.discount.BinNumberDto;
import com.ccys.db.vo.discount.BinNumberPageQueryVo;
import com.ccys.db.vo.discount.ServicesAndPackagesVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.text.ParseException;

/**
 * @program: WhiteCoat
 * @description: BIN编号接口
 * @author: ZhangJingCan
 * @create: 2023-12-15 09:47
 **/

@RestController
@RequestMapping("discount")
@Api(tags = "discount-BIN编号接口")
public class BinNumberController {

    @Autowired
    private BinNumberService binNumberService;


    
    @GetMapping("findListServicesAndPackages")
    @ApiOperation("查询Services和Packages集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "groupId", value = "groupId", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult<ServicesAndPackagesVo, Object> findListServicesAndPackages(String groupId) {
        return binNumberService.findListServicesAndPackages(groupId);
    }


    
    @PostMapping("saveBinNumber")
    @ApiOperation("保存BIN编号")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "对象id/修改必传", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "名称", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "状态", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "startDate", value = "开始日期", required = true, dataType = "date", paramType = "query"),
            @ApiImplicitParam(name = "endDate", value = "结束日期", required = false, dataType = "date", paramType = "query"),
            @ApiImplicitParam(name = "number", value = "number", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "limitUsage", value = "0表示无限次数", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "discountType", value = "0:free delivery(快递费用免费);1:fixed $ off bill(账单抵扣金额);2:% off bill(账单打折);3:fixed $ off consultation(问诊费用抵扣金额);4:% off consultation(问诊费用打折);5:fixed $ off delivery(快递费用抵扣金额);6:% off delivery(快递费用打折);7:%off consultation + % off delivery(问诊费用与快递费用同时打折)", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "reusable", value = "同一个人是否可以重复使用 0 否 1 是", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "discountAmount", value = "额度(金额或者抵扣的百分比)", required = true, dataType = "double", paramType = "query"),
            @ApiImplicitParam(name = "discountLabel", value = "折扣标签", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "afterHoursConsultFloor", value = "计算优惠金额与 floor 做比较，哪个大就用哪个值来付款", required = true, dataType = "double", paramType = "query"),
            @ApiImplicitParam(name = "officeHoursConsultFloor", value = "计算优惠金额与 floor 做比较，哪个大就用哪个值来付款", required = true, dataType = "double", paramType = "query"),
            @ApiImplicitParam(name = "expired", value = "是否过期 0 否 1 是（只有在CMS操作）", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "expirationMessage", value = "过期时的提醒消息", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "discountOffService", value = "是否支持打折医疗服务", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "discountAmountService", value = "discountOffService为1的时候这个字段必传", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "services", value = "这是一个集合数据，里面的字段只需要传：serviceId,packageId", required = false, dataType = "string", paramType = "query"),
    })
    public ResponseResult saveBinNumber(@RequestBody BinNumberDto dto) throws ParseException {
        return binNumberService.saveBinNumber(dto);
    }

    
    @DeleteMapping("binNumber")
    @ApiOperation("根据ID删除BIN编号")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "对象id", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult deleteBinNumber(@ApiIgnore BinNumberDto dto) {
        return binNumberService.deleteBinNumber(dto);
    }

    
    @GetMapping("binNumber")
    @ApiOperation("分页查询BIN编号")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "name", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "discountType", value = "0:free delivery(快递费用免费);1:fixed $ off bill(账单抵扣金额);2:% off bill(账单打折);3:fixed $ off consultation(问诊费用抵扣金额);4:% off consultation(问诊费用打折);5:fixed $ off delivery(快递费用抵扣金额);6:% off delivery(快递费用打折);7:%off consultation + % off delivery(问诊费用与快递费用同时打折)/查询所有传null", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "0/1,查询所有传null", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "startDate", value = "开始日期,格式:yyyy-MM-dd", required = false, dataType = "date", paramType = "query"),
            @ApiImplicitParam(name = "endDate", value = "结束日期,格式:yyyy-MM-dd", required = false, dataType = "date", paramType = "query"),
            @ApiImplicitParam(name = "orderByStr",
                    value = "(默认传：t1.created_on descend),(左到右依次:t1.name,t1.number,t1.discount_type,t1.discount_amount,t1.discount_label,t1.limit_usage,t1.start_date,t1.end_date,t1.reusable,t1.status,t2.user_fullname,t1.created_on)",
                    required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult<PageInfo<BinNumberPageQueryVo>, Object> findPageBinNumber(@ApiIgnore BinNumberDto dto) {
        return binNumberService.findPageBinNumber(dto);
    }

    
    @PutMapping("binNumber/status")
    @ApiOperation("根据ID修改BIN编号状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "对象id", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "状态：0-禁用，1-启用", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult updateBinNumberStatus(@ApiIgnore BinNumberDto dto) {
        return binNumberService.updateBinNumberStatus(dto);
    }

    
    @GetMapping("findServices")
    @ApiOperation("点击详情时-根据binId查询Services")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "对象id", required = true, dataType = "string", paramType = "query"),
    })
    public ResponseResult<ServicesAndPackagesVo, Object> findServices(@ApiIgnore BinNumberDto dto) {
        return binNumberService.findServices(dto);
    }

}
